﻿using CommonAsyncDemoFunctions;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SimpleAsyncConsole
{
	class SimpleConsole
	{
		static void Main(string[] args)
		{
			Stopwatch timer = new Stopwatch();
			timer.Start();

			#region Other Async File Loading Options
			//Here are some other options for reloading fortunes that use 
			//different types of async methods
			//var loadtask = FileLoader.ReloadFortunes();
			//var loadtask = FileLoader.ReloadFortunesAsyncSequential();
			//var loadtask = FileLoader.ReloadFortunesAsyncContinue();
			//loadtask.Wait();
			//FileLoader.ReloadFortunesParallelLoop();
			#endregion

			var task = FileLoader.GetFortuneAsync();

			#region With Error Handling Extension
			//var task = FileLoader.GetFortuneAsync().HandleErrors();
			//var task = FileLoader.GetFortuneAsync().HandleErrors(
			//	(ex) => Console.WriteLine("From the Handler: " + ex.Message));
			
			#endregion

			//If you don't wait for the task first, the count will be off, because 
			//the task won't be 
			task.Wait(); 

			Console.WriteLine("Fortunes Loaded: " + FileLoader.GetCount() + " Random Fortune: " + task.Result);
			
			Console.WriteLine("Timer:" + timer.Elapsed);
			Console.ReadKey();
		}
	}
}
